package top.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResponseResult;
import top.api.domain.dto.LinkAddDto;
import top.api.domain.dto.LinkUpdateDto;
import top.api.domain.dto.LinkUpdateStatusDto;
import top.api.service.LinkService;

@RestController
@RequestMapping("/content/link")
@Api(tags = "友链管理")
public class LinkController {
    @Autowired
    private LinkService linkService;

    @GetMapping("/list")
    @ApiOperation(value = "友链分页查询")
    @PreAuthorize("@ps.hasPermission('content:link:query')")
    public ResponseResult getLinkPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize,String name,String status){
        return linkService.getLinkPage(pageNum,pageSize,name,status);
    }

    @PostMapping
    @ApiOperation(value = "新增友链")
    @PreAuthorize("@ps.hasPermission('content:link:add')")
    public ResponseResult addLink(@RequestBody LinkAddDto linkAddDto){
        return linkService.addLink(linkAddDto);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询友链详情")
    @PreAuthorize("@ps.hasPermission('content:link:query')")
    public ResponseResult getLinkInfo(@PathVariable Long id){
        return linkService.getLinkInfo(id);
    }

    @PutMapping
    @ApiOperation(value = "修改友链")
    @PreAuthorize("@ps.hasPermission('content:link:edit')")
    public ResponseResult updateLink(@RequestBody LinkUpdateDto linkUpdateDto){
        return linkService.updateLink(linkUpdateDto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除友链")
    @PreAuthorize("@ps.hasPermission('content:link:remove')")
    public ResponseResult deleteLink(@PathVariable Long id){
        return linkService.deleteLink(id);
    }

    @PutMapping("/changeLinkStatus")
    @ApiOperation(value = "审核友链")
    @PreAuthorize("@ps.hasPermission('content:link:edit')")
    public ResponseResult changeLinkStatus(@RequestBody LinkUpdateStatusDto linkUpdateDto){
        return linkService.updateLinkStatus(linkUpdateDto);
    }
}
